package top.hcode.hoj.controller.oj;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.hcode.hoj.annotation.AnonApi;
import top.hcode.hoj.common.result.CommonResult;
import top.hcode.hoj.pojo.entity.user.Clazz;

import top.hcode.hoj.pojo.entity.user.Major;
import top.hcode.hoj.service.oj.ClazzService;

import java.util.List;

@RestController
@RequestMapping("/api/oj/clazz")
public class ClazzController {

    @Autowired
    private ClazzService clazzService;

    //此方法是前端注册的时候，根据选择的专业查找班级
    @GetMapping("/majorfandclazz")
    @AnonApi
    public CommonResult<List<Clazz>> majorfandclazz(@RequestParam(value = "selectedId") String selectedId) {
        return clazzService.getdeplists(selectedId);
    }

    //管理员后台的list、、/list_list
    @GetMapping("/list_list")
    public CommonResult<List<Clazz>> getMajorlist() {
        return clazzService.getLits();
    }

    //新增方法addclazz
    @PostMapping("/addclazz")
    public CommonResult<Void> addclazz(@RequestBody Clazz clazz) {
        if (clazz.getMajorid() == null|| clazz.getMajorid().equals("")) {
            return  CommonResult.errorResponse("专业不可以为空");
        }
        if(clazz.getName() == null || clazz.getName().equals("")){
            return  CommonResult.errorResponse("班级名称不可以为空");
        }
        return clazzService.addclazz(clazz);
    }

    @PostMapping("/updateclazz")
    public CommonResult<Void> updateclazz(@RequestBody Clazz clazz) {
        return clazzService.updateclazz(clazz);
    }

    @DeleteMapping("/deleteclazz")
    public CommonResult<Void> deleteclazz(@RequestBody Clazz clazz) {
        return clazzService.deleteclazz(clazz);
    }

}
